package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteProdInstFunc;
import com.iwhalecloud.bss.kite.service.attr.data.CustAttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Iterator;
import java.util.Map;
import java.util.Objects;

public class SafeCantChangeAttrHandler extends AbstractAttrHandler<KiteInst, CustAttrData> {
    @Autowired
    private IQuerySceneInstService querySceneInstService;
    @Override
    public void onShow(KiteAttr attr, KiteInst inst, CustAttrData data) {
        //置灰整个模块
        String sceneInstId = data.getSceneInstId();
        if(KiteStringUtils.equalsAny(inst.getActionType().name(), KeyConsts.ACTION_TYPE_M,KeyConsts.ACTION_TYPE_K)){
            //如果抗D典型E套餐  套餐内弹窗需置灰不可编辑
            String safe_kd_ise = querySceneInstService.getExtParameterValue(sceneInstId, "SAFE_KD_ISE");
            boolean isENoEdit = false;
            //if(KiteStringUtils.equals(safe_kd_ise,"T")){
                KiteProdInstFunc prodInstFunc = querySceneInstService.getProdInstFunc(data.getCustId(), inst.getInstId());
                if(Objects.nonNull(prodInstFunc)){
                    if(KiteStringUtils.equalsAny(prodInstFunc.getProdId(),"202102177023","202102177024","20210326006")){
                        isENoEdit = true;
                    }
                }
            //}
            if((KiteStringUtils.equals(safe_kd_ise,"T")&&isENoEdit)||!isENoEdit){
                Map<String, KiteAttr> attrMap = inst.getAttrMap();
                Iterator<Map.Entry<String, KiteAttr>> iterator = attrMap.entrySet().iterator();
                while (iterator.hasNext()){
                    Map.Entry<String, KiteAttr> kiteAttrEn = iterator.next();
                    kiteAttrEn.getValue().setIsEdit(KeyConsts.IFTRUE_F);
                }
            }
        }
        super.onShow(attr, inst, data);
    }

/*    @Override
    public void before(KiteAttr attr, KiteInst inst, String value, CustAttrData data) {
        if(KiteStringUtils.equalsAny(inst.getActionType().name(), KeyConsts.ACTION_TYPE_M,KeyConsts.ACTION_TYPE_K)){
            Map<String, KiteAttr> attrMap = inst.getAttrMap();
            Iterator<Map.Entry<String, KiteAttr>> iterator = attrMap.entrySet().iterator();
            while (iterator.hasNext()){
                Map.Entry<String, KiteAttr> kiteAttrEn = iterator.next();
                //kiteAttrEn.getValue().setIsEdit(KeyConsts.IFTRUE_F);
            }

        }
        super.before(attr, inst, value, data);
    }*/
}
